/**   
 * @Title: SportteryFootballGetTeamListCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.sportteryfootball 
 * @Description: (通讯接口,代码10039) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-8-3 上午10:50:42  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.sportteryfootball;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Key;
import com.esun.model.sportteryfootball.SportteryFootballLotteryInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.log.EDebug;

/**
 * @ClassName: SportteryFootballGetTeamListCommunicater
 * @Description: (获取联赛球队列表)
 * @author: City Jiangsy@500wan.com
 * @date: 2011-8-3 上午10:50:42
 * 
 */
public class SportteryFootballGetTeamListCommunicater extends ServerCommunicater {
	private String msgServer; // 服务器信息
	private boolean isSucceed = false;

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String msgServer) {
		this.msgServer = msgServer;
	}

	public boolean isGetTeamListSucceed() throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_SPORTTERFOOTBALL_GETTEAMLIST));
		// 写入服务器返回信息
		super.getServerResponse(list, true);
		setMsgServer(super.getErrorMSG());
		if (super.getState() == 100) {

			// 测试用语句,待删除
			setMsgServer(super.getResult().get(Key.KEY_TEAM));

			isSucceed = true;
		} else {
			isSucceed = false;
		}
		return isSucceed;
	}

	public void updateTeamInfo() {
		SportteryFootballLotteryInfo.getSportteryFootballLotteryInfo().getSimpleLeagueList().clear();
		try {
			String[] strResults = (super.getResult().get(Key.KEY_TEAM)).split("\\|");
			String[] strImageId = (super.getResult().get(Key.KEY_IMAGEID)).split("\\|");
			for (int i = 0; i < strResults.length; i++) {
				Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
				hashtable.put(Key.KEY_IS_CHECKED, true);
				hashtable.put(Key.KEY_SAISHI_NAME, strResults[i]);
				hashtable.put(Key.KEY_IMAGE_ID, strImageId[i]);
				SportteryFootballLotteryInfo.getSportteryFootballLotteryInfo().getSimpleLeagueList().add(hashtable);
				EDebug.o(this, strResults[i] + strImageId[i]);
			}
		} catch (Exception e) {
			// TODO: handle exception
			EDebug.o(this, "返回数据错误");
		}
		EDebug.o(this, "the list size is =" + SportteryFootballLotteryInfo.getSportteryFootballLotteryInfo().getSimpleLeagueList().size());
	}

	/**
	 * @Title: mapItem
	 * @Description: (工具类,用于构建AraayList单条内容)
	 * @param @param name 参数名
	 * @param @param value 参数值
	 * @param @return map
	 * @return HashMap<String,String> 返回类型
	 * @throws
	 */
	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
